package setting

import (
	"github.com/gin-gonic/gin"
	"likeadmin/admin/schemas/req"
	"likeadmin/admin/service/setting"
	"likeadmin/core"
	"likeadmin/core/response"
	"likeadmin/middleware"
	"likeadmin/util"
)

var RechargeGroup = core.Group("/setting/recharge", newRechargeHandler, regRecharge, middleware.TokenAuth())

func newRechargeHandler(srv setting.IRechargeSettingService) *rechargeHandler {
	return &rechargeHandler{srv: srv}
}

func regRecharge(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *rechargeHandler) {
		rg.GET("/get", handle.detail)
		rg.POST("/set", handle.edit)

	})
}

type rechargeHandler struct {
	srv setting.IRechargeSettingService
}

func (h rechargeHandler) detail(c *gin.Context) {

	res, err := h.srv.Detail(c)
	response.CheckAndRespWithData(c, res, err)
}

// edit setting编辑
func (h rechargeHandler) edit(c *gin.Context) {
	var editReq req.RechargeSettingEditReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &editReq)) {
		return
	}
	response.CheckAndResp(c, h.srv.Edit(c, editReq))
}
